#!/bin/sh

. /opt/etc/clutch.conf

if [ -z "$1" ] ; then
    case `echo "$0" | sed 's:^.*/\(.*\):\1:g'` in
        S??*) rc="start" ;;
        K??*) rc="stop" ;;
        *) rc="usage" ;;
    esac
else
    rc="$1"
fi

case "$rc" in
    start)
	echo "Starting transmission-daemon"
	echo "${HOME}/.transmission/daemon/socket" > \
	 /opt/share/www/lighttpd/clutch/remote/data/socket.txt
	/opt/bin/transmission-daemon -p ${PIDFILE}
        ;;
    stop)
        if [ -n "`pidof transmission-daemon`" ]; then
            echo "Stopping transmission-daemon"
            kill `cat ${PIDFILE}` 2> /dev/null
        fi
        ;;
    restart)
        "$0" stop
        sleep 10
        "$0" start
        ;;
    *)  
        echo "Usage: $0 (start|stop|restart|usage)"
        ;;
esac

exit 0
